home *** CD-ROM | disk | FTP | other *** search
/ Plug-In Power Pack for Netscape Communicator / Plug-In Power Pack for Netscape Communicator.iso / plugins / dataviews / dvtools / examples / windows / mfc_mdi / mfc_mdi.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1997-05-08  |  7.3 KB  |  235 lines

  1. // mfc_mdi.cpp : Defines the class behaviors for the application.
  2. //
  3.  
  4. /////////////////////////////////////////////////////////////////////////////
  5. //
  6. //    DataViews Multiple Document Inteface (MDI) example program.
  7. //
  8. //    Introduction:
  9. //    -------------
  10. //
  11. //    This programs provides a simple boilerplate example of how to display
  12. //    DataViews views through the Document-View architecture provided by
  13. //  Mircosoft's Foundation Classes (MFC) in an MDI program.
  14. //
  15. //    What this program does is to load in four previously created DataViews
  16. //    views (cleverly named view1.v, view2.v, view3.v, and view4.v), display
  17. //    them in a MDI child frame and continously update each view's dynamics.
  18. //
  19. //    The DataViews views can be closed, (de)iconified, or reopened, or
  20. //    completely different views (as long as they are valid DataViews views)
  21. //  may be loaded.  In addition, the child windows can be moved or resized,
  22. //    as well as cascaded or tiled.
  23. //
  24. //    This example program is not an exhaustive example by any means, but it
  25. //  does provide a solid basis for evolving more sophisticated programs.
  26. //
  27. //
  28. //    Getting Started:
  29. //    ----------------
  30. //
  31. //    As you might expect, the InitInstance() method below is where things
  32. //  gets things started: it makes the call to TInit() which intializes the
  33. //  DataViews toolkit and calls the CMultiDocTemplate method OpenDocumentFile()
  34. //    to load the four initial views.
  35. //
  36. //    The ExitInstance() overridable is where the call to the DataViews
  37. //    TTerminate() routine is made to cleanup DataViews.
  38. //
  39. //    Everything else in the middle that makes up a simple DV-Tools program,
  40. //    resides in the CDocument and CView subclasses (CMfc_mdiDoc & CMfc_mdiView
  41. //    respectivly).  This structure still follows the basic canonical form
  42. //    of a DV-Tools program (See Chapter 3 of the DV-Tools User's Guide), with
  43. //    the components of Init-Run-Terminate being integrated into the MFC
  44. //    Document-View architecture through subclassing.
  45. //
  46. //    Perhaps the best (and most obvious) way to digested this example by simply
  47. //    following the flow of control, quickly moving into the body of the
  48. //  OpenDocumentFile() method below, following the loading of the view and
  49. //    the creation of the screen object and its drawport, starting the timer
  50. //    used to continously display dynamics, and finally how the view is closed.
  51. //
  52. //    Also pay close attention to the OnResize() and OnDraw() methods of the
  53. //    CView object.
  54. //
  55. /////////////////////////////////////////////////////////////////////////////
  56.  
  57.  
  58. #include "stdafx.h"
  59. #include "mfc_mdi.h"
  60. #include "MainFrm.h"
  61. #include "ChildFrm.h"
  62. #include "mfc_mdiDoc.h"
  63. #include "mfc_mdiView.h"
  64.  
  65. #ifdef _DEBUG
  66. #define new DEBUG_NEW
  67. #undef THIS_FILE
  68. static char THIS_FILE[] = __FILE__;
  69. #endif
  70.  
  71. /////////////////////////////////////////////////////////////////////////////
  72. // CMfc_mdiApp
  73.  
  74. BEGIN_MESSAGE_MAP(CMfc_mdiApp, CWinApp)
  75.     //{{AFX_MSG_MAP(CMfc_mdiApp)
  76.     ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
  77.         // NOTE - the ClassWizard will add and remove mapping macros here.
  78.         //    DO NOT EDIT what you see in these blocks of generated code!
  79.     //}}AFX_MSG_MAP
  80.     // Standard file based document commands
  81.     ON_COMMAND(ID_FILE_NEW, CWinApp::OnFileNew)
  82.     ON_COMMAND(ID_FILE_OPEN, CWinApp::OnFileOpen)
  83.     // Standard print setup command
  84.     ON_COMMAND(ID_FILE_PRINT_SETUP, CWinApp::OnFilePrintSetup)
  85. END_MESSAGE_MAP()
  86.  
  87. /////////////////////////////////////////////////////////////////////////////
  88. // CMfc_mdiApp construction
  89.  
  90. CMfc_mdiApp::CMfc_mdiApp()
  91. {
  92.     // TODO: add construction code here,
  93.     // Place all significant initialization in InitInstance
  94. }
  95.  
  96. /////////////////////////////////////////////////////////////////////////////
  97. // The one and only CMfc_mdiApp object
  98.  
  99. CMfc_mdiApp theApp;
  100.  
  101. /////////////////////////////////////////////////////////////////////////////
  102. // CMfc_mdiApp initialization
  103.  
  104. BOOL CMfc_mdiApp::InitInstance()
  105. {
  106.     // Standard initialization
  107.     // If you are not using these features and wish to reduce the size
  108.     //  of your final executable, you should remove from the following
  109.     //  the specific initialization routines you do not need.
  110.  
  111. #ifdef _AFXDLL
  112.     Enable3dControls();            // Call this when using MFC in a shared DLL
  113. #else
  114.     Enable3dControlsStatic();    // Call this when linking to MFC statically
  115. #endif
  116.  
  117.     LoadStdProfileSettings();  // Load standard INI file options (including MRU)
  118.  
  119.     ////////////////////////////////////////////////////////////////////////
  120.     //
  121.     //    Intialize DataViews toolkit...
  122.     //
  123.     TInit( (char*)0, (char*)0 );
  124.  
  125.  
  126.     // Register the application's document templates.  Document templates
  127.     //  serve as the connection between documents, frame windows and views.
  128.  
  129.     CMultiDocTemplate* pDocTemplate;
  130.     pDocTemplate = new CMultiDocTemplate(
  131.         IDR_MFC_MDTYPE,
  132.         RUNTIME_CLASS(CMfc_mdiDoc),
  133.         RUNTIME_CLASS(CChildFrame), // custom MDI child frame
  134.         RUNTIME_CLASS(CMfc_mdiView));
  135.     AddDocTemplate(pDocTemplate);
  136.  
  137.     // create main MDI Frame window
  138.     CMainFrame* pMainFrame = new CMainFrame;
  139.     if (!pMainFrame->LoadFrame(IDR_MAINFRAME))
  140.         return FALSE;
  141.     m_pMainWnd = pMainFrame;
  142.  
  143.     // Parse command line for standard shell commands, DDE, file open
  144.     CCommandLineInfo cmdInfo;
  145.  
  146.     // Set the m_nShellCommand field to FileNothing instead of FileNew.
  147.     // Prevents creation of an initial blank document.
  148.     cmdInfo.m_nShellCommand = CCommandLineInfo::FileNothing;  
  149.   
  150.     ParseCommandLine(cmdInfo);
  151.  
  152.     // Dispatch commands specified on the command line
  153.     if (!ProcessShellCommand(cmdInfo))
  154.         return FALSE;
  155.  
  156.     ////////////////////////////////////////////////////////////////////////
  157.     //
  158.     //    For this demo, we are starting by hard coding the the names of
  159.     //    four standard views to be intially loaded and displayed...
  160.     //
  161.     pDocTemplate->OpenDocumentFile("view1.v");
  162.     pDocTemplate->OpenDocumentFile("view2.v");
  163.     pDocTemplate->OpenDocumentFile("view3.v");
  164.     pDocTemplate->OpenDocumentFile("view4.v");
  165.  
  166.     // The main window has been initialized, so show and update it.
  167.     pMainFrame->ShowWindow(m_nCmdShow);
  168.     pMainFrame->UpdateWindow();
  169.  
  170.     return TRUE;
  171. }
  172.  
  173. /////////////////////////////////////////////////////////////////////////////
  174. // CAboutDlg dialog used for App About
  175.  
  176. class CAboutDlg : public CDialog
  177. {
  178. public:
  179.     CAboutDlg();
  180.  
  181. // Dialog Data
  182.     //{{AFX_DATA(CAboutDlg)
  183.     enum { IDD = IDD_ABOUTBOX };
  184.     //}}AFX_DATA
  185.  
  186.     // ClassWizard generated virtual function overrides
  187.     //{{AFX_VIRTUAL(CAboutDlg)
  188.     protected:
  189.     virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
  190.     //}}AFX_VIRTUAL
  191.  
  192. // Implementation
  193. protected:
  194.     //{{AFX_MSG(CAboutDlg)
  195.         // No message handlers
  196.     //}}AFX_MSG
  197.     DECLARE_MESSAGE_MAP()
  198. };
  199.  
  200. CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
  201. {
  202.     //{{AFX_DATA_INIT(CAboutDlg)
  203.     //}}AFX_DATA_INIT
  204. }
  205.  
  206. void CAboutDlg::DoDataExchange(CDataExchange* pDX)
  207. {
  208.     CDialog::DoDataExchange(pDX);
  209.     //{{AFX_DATA_MAP(CAboutDlg)
  210.     //}}AFX_DATA_MAP
  211. }
  212.  
  213. BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
  214.     //{{AFX_MSG_MAP(CAboutDlg)
  215.         // No message handlers
  216.     //}}AFX_MSG_MAP
  217. END_MESSAGE_MAP()
  218.  
  219. // App command to run the dialog
  220. void CMfc_mdiApp::OnAppAbout()
  221. {
  222.     CAboutDlg aboutDlg;
  223.     aboutDlg.DoModal();
  224. }
  225.  
  226. /////////////////////////////////////////////////////////////////////////////
  227. // CMfc_mdiApp commands
  228.  
  229. int CMfc_mdiApp::ExitInstance() 
  230. {
  231.     TTerminate();
  232.     
  233.     return CWinApp::ExitInstance();
  234. }
  235.